package com.ruoyi.framework.config;

import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import com.github.pagehelper.PageInterceptor;
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Properties;

@Configuration
public class PageHelperConfig {
    
    @Autowired
    private List<SqlSessionFactory> sqlSessionFactoryList;
    
    private final PageInterceptor pageInterceptor;
    
    public PageHelperConfig() {
        pageInterceptor = new PageInterceptor();
        Properties properties = new Properties();
        properties.setProperty("helperDialect", "db2");
        properties.setProperty("reasonable", "true");
        pageInterceptor.setProperties(properties);
    }
    
    @PostConstruct
    public void addPageInterceptor() {
        for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
            sqlSessionFactory.getConfiguration().addInterceptor(pageInterceptor);
        }
    }
    
    public PageInterceptor getPageInterceptor() {
        return pageInterceptor;
    }
} 